package com.ggb.reactive.service

import com.ggb.reactive.domain.dto.SetmealPageQueryDTO
import com.ggb.reactive.domain.entity.Setmeal
import com.ggb.reactive.domain.entity.ShoppingCart
import com.ggb.reactive.model.PageResult
import com.ggb.reactive.model.Result
import lombok.RequiredArgsConstructor
import org.springframework.data.domain.PageImpl
import org.springframework.data.domain.PageRequest
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate
import org.springframework.data.relational.core.query.Criteria
import org.springframework.data.relational.core.query.Query
import org.springframework.r2dbc.core.DatabaseClient
import org.springframework.stereotype.Service
import reactor.core.publisher.Mono


@Service
@RequiredArgsConstructor
class ShoppingCartService(
    private val r2dbcEntityTemplate: R2dbcEntityTemplate,
) {
    /**
     * 分页查询
     */

    fun findShoppingCartByCriteria(shoppingCart: ShoppingCart): Mono<List<ShoppingCart>> {
        var criteria = Criteria.empty()

        shoppingCart.userId?.let {
            criteria = criteria.and("user_id").`is`(it)
        }
        shoppingCart.setmealId?.let {
            criteria = criteria.and("setmeal_id").`is`(it)
        }
        shoppingCart.dishId?.let {
            criteria = criteria.and("dish_id").`is`(it)
        }
        shoppingCart.dishFlavor?.let {
            criteria = criteria.and("dish_flavor").`is`(it)
        }
        val query = Query.query(criteria)
        return r2dbcEntityTemplate.select(query, ShoppingCart::class.java).collectList()

    }

}